import common.pagedriver
import os
from common.logutil import logger
from common import CSVreader
from pageobject import login
from pageobject import logout
from pageobject import register
data_login=CSVreader.csvreader_list(os.path.dirname(os.path.dirname(__file__))+'\data\casedata\LoginData.csv')
data_register=CSVreader.csvreader_list(os.path.dirname(os.path.dirname(__file__))+'\data\casedata\RegisterDate.csv')
class Testcase:
    def __init__(self):
        pass
    def test_login(self):
        for i in data_login:
            result=login.login(i[0],i[1],i[2],int(i[3]))
            try:
                assert result
            except:
                logger.info(f'测试用例：{i[0]}——本条测试用例不通过！（登录用例）')
            finally:
                common.pagedriver.reset()
    def test_register(self):
        for i in data_register:
            result=register.Register().register(i[0],i[1],i[2],int(i[3]))
            try:
                assert result
            except:
                logger.info(f'{i[0]}——本条测试用例不通过（注册用例）')
            finally:
                common.pagedriver.reset()
    def test_logout(self,address,assertest,n):
        logout.Louout().logout(address)
        if n==1:
            try:
                common.pagedriver.locater_Xpath(assertest)
                result=True
            except:
                result=False
        else:
            try:
                common.pagedriver.locater_Xpath(assertest)
                result=False
            except:
                result=True
        try:
            assert result
        except:
            logger.info('本条测试用例不通过！(退出登录）')
        finally:
            common.pagedriver.reset()
